using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[Serializable]
public class Stat
{
    [SerializeField] private int baseValue;
    [SerializeField] private List<int> modifiers;
    public delegate void OnModifierChangeEvent(int modifier);
    public OnModifierChangeEvent onAddModifierEvent;
    public OnModifierChangeEvent onRemoveModifierEvent;
    
    public int GetValue()
    {
        int finalValue = baseValue;
        foreach (int modifier in modifiers)
        {
            finalValue += modifier;
        }
        return finalValue;
    }

    

    public void SetValue(int _value)
    { 
        baseValue = _value;
    }

    public void AddModifier(int modifier)
    { 
        modifiers.Add(modifier);
        if (onAddModifierEvent != null)
        {
            onAddModifierEvent(modifier);
        }
    }

    public void RemoveModifier(int modifier)
    {
        modifiers.Remove(modifier);
        if (onRemoveModifierEvent != null)
        {
            onRemoveModifierEvent(modifier);
        }
    }
}
